<?php

namespace app\xiangji\controller;


use app\Request;
use app\xiangji\BaseController;
use app\common\helpers\Response;
use app\xiangji\services\DummyJottingService;
use app\xiangji\validates\DummyJottingValidate;
use think\App;
use think\exception\ValidateException;


class DummyJotting extends BaseController
{
    private $jottingService;

    public function __construct(DummyJottingService $jottingService)
    {
        $this->jottingService = $jottingService;
    }

    public function fetch(Request $request)
    {
        validate(DummyJottingValidate::class)->scene('fetch')->check($request->get());
        $result = $this->jottingService->fetch($request);
        return $this->success($result);
    }

    public function show($id)
    {
        $result = $this->jottingService->show($id);
        return $this->success($result);
    }

    public function store(Request $request)
    {
        // 校验数据
        validate(DummyJottingValidate::class)->scene('create')->check($request->post());
        // 逻辑处理
        $result = $this->jottingService->store($request);
        return $this->success($result);
    }

    public function delete($id)
    {
        $result = $this->jottingService->delete($id);
        return $this->success($result);
    }
}
